package GUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Example12 {
    public static void main(String[] args) {
        JFrame f=new JFrame("聊天窗口");
        f.setLayout(new BorderLayout());
        f.setSize(400,300);
        f.setLocation(300,200);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JTextArea showArea=new JTextArea(12,34);
        JScrollPane scrollPane=new JScrollPane(showArea);
        showArea.setEditable(false);
        JTextField inputField=new JTextField(20);
        JButton btn=new JButton("发送");
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String content=inputField.getText();
                if(content!=null&&!content.trim().equals("")){
                    showArea.append("本人输入信息"+content+"\n");
                }else {
                    showArea.append("聊天信息不能为空!!!"+"\n");
                }
                inputField.setText("");
            }
        });
        JPanel panel=new JPanel();
        JLabel label=new JLabel("聊天信息");
        panel.add(label);
        panel.add(inputField);
        panel.add(btn);
        f.add(scrollPane,BorderLayout.PAGE_START);
        f.add(panel,BorderLayout.PAGE_END);
        f.setVisible(true);
    }
}